package com.huilian.tool.work.weixin.service.impl;


import com.huilian.tool.work.weixin.service.WorkWeiXinUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;


/**
 * @Author 少凡
 * @Date 2022-06-24 17:12
 * version 1.0
 */
@Slf4j
@Service
public class WorkWeiXinUserServiceImpl implements WorkWeiXinUserService {

    @Resource
    private RestTemplate restTemplate;


    @Override
    public String create() {
        return null;
    }

    @Override
    public String get(String accessToken, String userId) {
        StringBuilder url = new StringBuilder("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=")
                .append(accessToken).append("&userid=").append(userId);
        return restTemplate.getForObject(url.toString(), String.class);
    }

    @Override
    public String update() {
        return null;
    }

    @Override
    public String delete() {
        return null;
    }

    @Override
    public String getDepartmentUserList(String accessToken, Integer departmentId) {
        StringBuilder url = new StringBuilder("https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=")
                .append(accessToken).append("&department_id=").append(departmentId);

        String result = restTemplate.getForObject(url.toString(), String.class);

        return result;
    }
}
